//
//  ZSTabBar.swift
//  ZSWeibo
//
//  Created by zsj1992 on 16/4/6.
//  Copyright © 2016年 ichange. All rights reserved.
//

import UIKit

/// 自定义的tabBar,
class ZSTabBar: UITabBar {
    
    //懒加载的发布按钮
  lazy var btnPlus : UIButton = {
    
   let btn1 = UIButton()

    btn1.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: UIControlState.Normal)
    
    btn1.setBackgroundImage(UIImage(named: "tabbar_compose_button_selected"), forState: UIControlState.Selected)
    
    btn1.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: .Normal)
    btn1.setImage(UIImage(named: "tabbar_compose_icon_selected"), forState: .Selected)

    return btn1
    }()

    
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)

        self.addSubview(btnPlus)
        
    }

    
    
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override func layoutSubviews() {
        
        super.layoutSubviews()

        let W:CGFloat = self.bounds.width/5

        let H:CGFloat = bounds.height
        
        let Y:CGFloat = 0
        
        var index:Int = 0

        for subview in subviews{
            
            //如果subView是按
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                
                subview.frame = CGRectMake(CGFloat(index)*W, Y, W, H);

                index = index==1 ? index+2:index+1
                
            }
        }
        self.btnPlus.frame = CGRectMake(2*W, 0, W, H)
    }
}













